<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Explicit and non-explicit calls</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>

<body>

<div align="center">
<table class=allEncompassingTable >
 <tr>
  <td >
<p><a href="../index.html" TARGET="_top"><img src="images/homeImg.png"></a></p>



<h1>Explicit and non-explicit calls</h1>

<p>Some objects, such as <a href="proximitySensors.htm">proximity sensors</a>, normally require <em>handling</em> or calculations to be performed once per simulation step, to reflect a possible change in the scene. This handling can be done implicitely or explicitely, and those objects have a special setting related to that: an <strong>explicit handling</strong> flag. By default that flag is unchecked, which means that the object will be implicitely handled via the <a href="mainScript.htm">main script</a>. Indeed the following main script code will be executed and handle said objects once per simulation step:</p>

<pre class=lightRedBox>
sim.handleProximitySensor(sim.handle_all_except_explicit)</pre>


<p>Above code will perform proximity sensor computations, and any other script can then read the up-to-date calculation results with:</p>
<pre class=lightRedBox>
local calculationResult=sim.readProximitySensor(sensorHandle)</pre>

<p>Above code, unlike the previous, will not compute anything, but just read the calculation result. This is very convenient when calculation need to happen exactly once per simulation step and/or the calculation result is required by several scripts.</p>
<p>If however, an object requires less or more frequent calculations (e.g. several calculations within a same simulation step), then above mechanism does not work. In that case, the object should be flagged as <strong>explicit handling</strong>: from that moment on, the main script will not handle that object anymore, and it is the responsibility of another script to do this. For instance if the proximity sensor should only be handled once every other simulation step, a <a href="childScripts.htm">child script</a> could include following code:</p>


<pre class=lightRedBox>
function sysCall_init()
    sensorHandle=sim.getObjectHandle('/myProximitySensor')
end

function sysCall_sensing()
    handleSensor=not handleSensor
    if handleSensor then
        sim.handleProximitySensor(sensorHandle)
    end
end</pre>



<p>If new calculations need to be performed several times within a same simulation step (e.g. because an object or the sensor itself is moved more frequently), one could write:</p>

<pre class=lightRedBox>
function sysCall_init()
    sensorHandle=sim.getObjectHandle('/myProximitySensor')
end

function sysCall_sensing()
    for i=1,10,1 do
        local pos=sim.getObjectPosition(sensorHandle,-1)
        pos[3]=i/10
        sim.setObjectPosition(sensorHandle,-1,pos) -- e.g. move the sensor
        local calculationResults=sim.handleProximitySensor(sensorHandle)
    end
end
</pre>


<br>
<br>
 </tr>
</table> 
</div>  
  
  
</body>

</html>
